package com.monitor.web.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Author tanlian
 * @Date 2019/1/15 10:26
 * @Desc
 */
@Slf4j
@RestController
@RequestMapping("/kafka")
public class KafkaController {


    @Autowired
    private KafkaTemplate kafkaTemplate;

    @RequestMapping("/test")
    public Object kafkaTest(){

        String message = UUID.randomUUID().toString();
        ListenableFuture future = kafkaTemplate.send("app_log", message);
        future.addCallback(o -> System.out.println("send-消息发送成功：" + message), throwable -> System.out.println("消息发送失败：" + message));
        return "Success";
    }
}
